const CHAIN = 'product_name'
/**
 * key
 * 类型type：set，get，clear；
 * val
 */
export const cachesStorage = (key, type, val) => {
	let keys = CHAIN + '_' + key
	switch (type){
		case 'set':
			if (typeof val == "object") {
				// 如果是对象，就转字符串存储
				val = JSON.stringify(val)
			}
			window.sessionStorage.setItem(keys, val);
			break;
		case 'get':
			const data = window.sessionStorage.getItem(keys);
			if (data) {
				let val = data
				if ((data.indexOf('{') === 0 || data.indexOf('[') === 0) && data.indexOf(':') >= 0) {
					// 如果是字符串对象，就转对象
					val = JSON.parse(data)
				}
				return val
			} else {
				return false
			}
		case 'clear':
			window.sessionStorage.removeItem(keys);
			break;
		default:
			 console.log('type参数有误')
			 return false

	}
}
